package com.zjnx.train.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.zjnx.train.dao.UserDao;
import com.zjnx.train.entity.User;

/**
 * @author foo
 * @email foo@zjnx.com
 * @description:dao接口实现
 */
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

  @Override
  public void save(User user) {
    getHibernateTemplate().save(user);
  }

  @Override
  public void update(User user) {
    getHibernateTemplate().update(user);
  }

  @Override
  public void delete(Long id) {
    User user = findByKey(id);
    if (user != null) {
      getHibernateTemplate().delete(user);
    }
  }

  @Override
  public User findByKey(Long id) {
    return getHibernateTemplate().get(User.class, id);
  }

  @Override
  public List<User> findAll() {
    return getHibernateTemplate().loadAll(User.class);
  }

}
